package sz.szsmk.citizencard.ui.dialogs.dzsmk;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;

import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.bean.response.AdvertisementsRes;
import sz.szsmk.citizencard.ui.activity.IMainActivity;
import sz.szsmk.citizencard.ui.activity.YouzanActivity;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.ButtonUtils;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.util.JumpThirdView;
import sz.szsmk.citizencard.util.JumpUtils;


public class GreenTravelDialog  extends Dialog {

    View inflate;

    TextView tv_title;
    TextView tv_content;

    LinearLayout ll_bottonLayout;
    protected GreenTravelDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, R.style.alertdialog);
    }

    public GreenTravelDialog(@NonNull Context context) {
        super(context, R.style.greenTravel);
        int divierId = context.getResources().getIdentifier("android:id/titleDivider", null, null);
        View divider = findViewById(divierId);
        divider.setVisibility(View.GONE);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(LayoutInflater.from(getContext()).inflate(R.layout.dialog_adv, null));
        tv_title = findViewById(R.id.tv_title);
        tv_content = findViewById(R.id.tv_content);

        ll_bottonLayout = findViewById(R.id.ll_bottonLayout);

    }

    public void setData(AdvertisementsRes advertisementsRes){
        AdvertisementsRes.DataBean bean =  advertisementsRes.getData();
        tv_title.setText(bean.getTitle());
        tv_content.setText(bean.getDesc());

        ll_bottonLayout.removeAllViews();
        List<AdvertisementsRes.DataBean.DetailBean> detail = bean.getDetail();
        for(int i=0;i<detail.size();i++){
            View view = View.inflate(getContext(), R.layout.dialog_adv_buttonlayout, null);
            TextView tv_title = view.findViewById(R.id.tv_title);
            View viewLine = view.findViewById(R.id.view);
            tv_title.setText(detail.get(i).getTitle());

            view.setOnClickListener(new OnClickListenerForView(detail.get(i)));

            //隐藏最后一条的 底线
            if(i==detail.size()-1){
                viewLine.setVisibility(View.GONE);
            }
            ll_bottonLayout.addView(view);
        }

    }

    class OnClickListenerForView implements View.OnClickListener{
        AdvertisementsRes.DataBean.DetailBean detailBean;
        OnClickListenerForView(AdvertisementsRes.DataBean.DetailBean bean){
            this.detailBean = bean;
        }
        @Override
        public void onClick(View view) {
            JumpThirdView.baseToJumpView(getContext(), detailBean.getLinkUrl(), detailBean.getSysLabel()
                    , Integer.valueOf(detailBean.getNeedHeader()).intValue(), "");
        }
    }


}